import tkinter
from tkinter import *
from PIL import Image, ImageTk
import calculate
import capture
import time

root = Tk()
root.title("I care客车安全智能监测系统演示")
# root.geometry('1000x500')
root.resizable(width=False, height=True)
frame1 = Frame(root)
frame2 = Frame(root)

var = StringVar()
var.set('监测结果：\n')

textLabel = Label(frame1, text='I care客车安全智能监测系统演示', font=('幼圆', 20)).pack()
text_top = Label(frame1, text='需要对比的人脸', font=('幼圆', 15)).pack()


# 拍照
def cap():
    capture.capture('Facebase/0.jpg')   # 拍照函数
    # 把拍照的的照片显示出来
    image = Image.open('Facebase/0.jpg')
    photo = ImageTk.PhotoImage(image)
    tkinter.Label(frame1, image=photo).pack()
    Label.mainloop(frame1)
# 检测结果显示
def say():
    var.set('监测结果:\n\n' + calculate.main() + '\n')

# 添加人脸（乘客）存入到Facebase目录下
# 以时间戳命名
def add_face():
    capture.capture('Facebase/' + str(time.time()) + '.jpg')

Label(frame2, textvariable=var, font=('幼圆', 15)).pack(side=TOP)

bt_addFace = Button(frame2, text='添加', command=add_face).pack(side=LEFT)
bt_capture = Button(frame2, text='拍照', command=cap).pack(side=RIGHT)
bt_match = Button(frame2, text='监测', command=say).pack(side=BOTTOM)


frame1.pack(padx=10, pady=10)
frame2.pack(padx=10, pady=10)
root.mainloop()